package com.itheima.system.exception;


import com.itheima.controller.results.ErrorCode;

/**
 * Description: 前端请求异常，日志不输出ERROR级别
 * -----------------------------------------------
 * Author:      chenliuchun
 * Date:        2019-11-13 10:57
 * Revision history:
 * Date         Remark
 * --------------------------------------------------
 */

public class BizException extends RuntimeException {

    private static final long serialVersionUID = 9164117137727846171L;

    private String code;

    private String text;

    public BizException(String code) {
        this.code = code;
    }

    public BizException(String code, String message) {
        super(message);
        this.code = code;
        this.text = message;
    }

    public BizException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.name();
        this.text = errorCode.getMessage();
    }

    public BizException(ErrorCode errorCode, String message) {
        super(message);
        this.code = errorCode.name();
        this.text = message;
    }

    public BizException(String code, StackTraceElement[] stackTraceElements) {
        this.code = code;
        setStackTrace(stackTraceElements);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Override
    public String toString() {
        return "RequestException{" +
                "code='" + code + '\'' +
                ", text='" + text + '\'' +
                '}';
    }
}